//
//  SupervisionListCell.m
//  HengHuaSupervision
//
//  Created by XD-XY on 3/21/14.
//  Copyright (c) 2014 XD-XY. All rights reserved.
//  监造首页列表

#import "SupervisionListCell.h"
#import "XDHeader.h"
#import "XDTools.h"

@implementation SupervisionListCell

- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        // Initialization code
        [self makeView];
    }
    return self;
}

-(void)makeView
{
    CGFloat aheight = 122/2.0f;
    //序号
    self.numberLabel = [UILabel initLabel:CGRectMake(0, 0,130/2.0f,aheight) textFont:mHomepage_text_Font textColor:mHomepagelist_Text_Color textAlignment:NSTextAlignmentCenter];
    
    //设备编号
    self.assertIdLabel = [UILabel initLabel:CGRectMake(width_x(_numberLabel)+1, 0,361/2.0f,aheight) textFont:mHomepage_text_Font textColor:mHomepagelist_Text_Color textAlignment:NSTextAlignmentCenter];
    
    //名称
    self.assertNameLabel = [UILabel initLabel:CGRectMake(width_x(_assertIdLabel)+1, 0,425/2.0f,aheight) textFont:mHomepage_text_Font textColor:mHomepagelist_Text_Color textAlignment:NSTextAlignmentCenter];
    
    //型号
    self.assertModelLabel = [UILabel initLabel:CGRectMake(width_x(_assertNameLabel)+1, 0,361/2.0f,aheight) textFont:mHomepage_text_Font textColor:mHomepagelist_Text_Color textAlignment:NSTextAlignmentCenter];
    
    //生产厂家
    self.factoryNameLabel = [UILabel initLabel:CGRectMake(width_x(_assertModelLabel)+1, 0,425/2.0f,aheight) textFont:mHomepage_text_Font textColor:mHomepagelist_Text_Color textAlignment:NSTextAlignmentCenter];
    
    //标签数量
    self.tagsCountLabel = [UILabel initLabel:CGRectMake(width_x(_factoryNameLabel)+1, 0,130/2.0f,aheight) textFont:mHomepage_text_Font textColor:mHomepagelist_Text_Color textAlignment:NSTextAlignmentCenter];
    
    //贴标签按钮
    self.stickBtn = [UIButton initButton:CGRectMake(width_x(_tagsCountLabel)+1+15,12,mHomepage_stick_Normal_Img.size.width, mHomepage_stick_Normal_Img.size.height) btnNorImage:mHomepage_stick_Normal_Img btnPressBtn:mHomepage_stick_Highlight_Imag btnTitle:nil titleColor:nil titleFont:nil];
    
    self.photoImage = [[UIImageView alloc] initWithFrame:CGRectMake(10/2.0f,(aheight -mHomePage_List_Smallimage_Img.size.height)/2.0f,mHomePage_List_Smallimage_Img.size.width,mHomePage_List_Smallimage_Img.size.height)];
    _photoImage.image = mHomePage_List_Smallimage_Img;
    _photoImage.hidden =YES;
    
    
    [self addSubview:_numberLabel];
    [self addSubview:_assertIdLabel];
    [self addSubview:_assertNameLabel];
    [self addSubview:_assertModelLabel];
    [self addSubview:_factoryNameLabel];
    [self addSubview:_tagsCountLabel];
    [self.contentView addSubview:_stickBtn];
    [self addSubview:_photoImage];
    
    //cell未选中效果
    self.diselectBg = [[UIImageView alloc] init];
    _diselectBg.frame = CGRectMake(0, 0, self.frame.size.width,self.frame.size.height);
    self.backgroundView = _diselectBg;
    
    //cell选中效果
    self.selectBg = [[UIImageView alloc] init];
    _selectBg.frame = CGRectMake(0, 0, self.frame.size.width,self.frame.size.height);
    _selectBg.image = [XDTools stretchableImag:mHomepage_Cell_select_Img];
    self.selectedBackgroundView = _selectBg;

}

-(void)isHarderTableViewCell
{
    //表头改变字体大小和颜色
    [self changeLabelTextcolorAndFont:_numberLabel];
    [self changeLabelTextcolorAndFont:_assertIdLabel];
    [self changeLabelTextcolorAndFont:_assertNameLabel];
    [self changeLabelTextcolorAndFont:_assertModelLabel];
    [self changeLabelTextcolorAndFont:_factoryNameLabel];
    [self changeLabelTextcolorAndFont:_tagsCountLabel];
    
    //创建分割线
    UIImage * image = mHomepage_Head_Cutline_Img;
    UIImageView * lineView1  = [[UIImageView alloc] initWithFrame:CGRectMake(width_x(_numberLabel), 0, image.size.width, image.size.height)];
    lineView1.image = image;
    UIImageView * lineView2  = [[UIImageView alloc] initWithFrame:CGRectMake(width_x(_assertIdLabel), 0, image.size.width, image.size.height)];
    lineView2.image = image;
    UIImageView * lineView3  = [[UIImageView alloc] initWithFrame:CGRectMake(width_x(_assertNameLabel), 0, image.size.width, image.size.height)];
    lineView3.image = image;
    UIImageView * lineView4  = [[UIImageView alloc] initWithFrame:CGRectMake(width_x(_assertModelLabel), 0, image.size.width, image.size.height)];
    lineView4.image = image;
    UIImageView * lineView5  = [[UIImageView alloc] initWithFrame:CGRectMake(width_x(_factoryNameLabel), 0, image.size.width, image.size.height)];
    lineView5.image = image;
    UIImageView * lineView6  = [[UIImageView alloc] initWithFrame:CGRectMake(width_x(_tagsCountLabel), 0, image.size.width, image.size.height)];
     lineView6.image = image;
    
    [self addSubview:lineView1];
    [self addSubview:lineView2];
    [self addSubview:lineView3];
    [self addSubview:lineView4];
    [self addSubview:lineView5];
    [self addSubview:lineView6];
    
    _stickBtn.hidden = YES;
}

-(void)changeLabelTextcolorAndFont:(UILabel *)label
{
    label.textColor = mHomepage_Head_Text_Color;
    label.font = mHomepage_Head_text_Font;
}
//-(void)setHighlighted:(BOOL)highlighted animated:(BOOL)animated
//{
//    [super setHighlighted:highlighted animated:YES];
//    if (highlighted){
//        [_stickBtn setHighlighted:NO];
//    }
//}
- (void)setSelected:(BOOL)selected animated:(BOOL)animated
{
    [super setSelected:selected animated:animated];

    if(selected){
        //[_stickBtn setHighlighted:NO];
        //[_stickBtn setHighlighted:YES];
       // [_stickBtn setBackgroundImage:mHomepage_stick_Highlight_Imag forState:UIControlStateHighlighted];
    }else{

    }
    
    // Configure the view for the selected state
}

@end
